package com.itbac.springsecurityoauth2demo.pojo;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 用户实体
 * @author: BacHe
 * @email: 1218585258@qq.com
 * @Date: 2021/3/27 11:19
 */
public class User implements UserDetails {
    //用户
    private String username;
    //密码
    private String password;
    //权限或角色
    private List<GrantedAuthority> authorities;

    public User() {
    }

    public User(String username, String password, List<GrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.authorities = authorities;
    }

    public User setUsername(String username) {
        this.username = username;
        return this;
    }

    public User setPassword(String password) {
        this.password = password;
        return this;
    }

    public User setAuthorities(List<GrantedAuthority> authorities) {
        this.authorities = authorities;
        return this;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        //后面跟进数据库查出
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        //后面跟进数据库查出
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        //后面跟进数据库查出
        return true;
    }

    @Override
    public boolean isEnabled() {
        //后面跟进数据库查出
        return true;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", authorities=" + authorities +
                '}';
    }
}
